<template>
  <el-container class="my-container">
    <el-aside width="200px">
      <img src="@/assets/images/logo.png" alt="" style="width: 140px" />
      <el-menu
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        background-color="#223344"
        text-color="#fff"
        active-text-color="#409EFF"
        router
      >
        <el-menu-item index="/">
          <i class="el-icon-s-home"></i>
          数据概览
        </el-menu-item>
        <el-menu-item index="/article">
          <i class="el-icon-document"></i>
          内容管理
        </el-menu-item>
        <el-menu-item index="/publish">
          <i class="el-icon-s-promotion"></i>
          发布文章
        </el-menu-item>
        <el-menu-item index="/user">
          <i class="el-icon-user-solid"></i>
          用户中心
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <span @click="$router.push('/user')">{{ user.name||user.mobile }}</span>
        <el-link :underline="false" icon="el-icon-unlock" @click="Back"
          >退出</el-link
        >
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>

import auth from '@/utils/token'
import eventBus from '@/utils/eventBus'

export default {
  data () {
    return {
      user: {}
    }
  },
  methods: {
    Back () {
      this.$confirm('确定要退出吗', '温馨提示', {
        confirmButtonText: '狠心退出',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        auth.delToken()
        this.$message({
          type: 'success',
          message: '退出成功!'
        })
        this.$router.push('/login')
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消退出'
        })
      })
    }
  },
  async created () {
    const res = await this.$http.get('/v1_0/user/profile')
    this.user = res.data.data
    eventBus.$on('updateUser', (profile) => {
      this.user = profile
    })
  }
}
</script>
<style scoped>
.my-container {
  height: 100vh;
}
.el-aside {
  background-color: #223344;
  border-right: none;
  img {
    margin-top: 10px;
    margin-left: 30px;
  }
}
.el-header {
  height: 100px;
  /* background-color: skyblue; */
  border-bottom: 1px solid #f4f4f4;
  display: flex;
  justify-content: end;
  align-items: center;
  gap: 10px;
  /* gap 组件之间的间距 */
}
.el-main {
  /* background-color: yellow; */
  margin: 0;
  padding: 0;
  /* background-image: url("@/assets/images/chart.png");
  background-repeat: no-repeat;
  background-size: cover; */
}
</style>
